package com.shreecon.lms.manager;

import java.util.HashMap;
import java.util.List;

import com.shreecon.lms.common.DateUtil;
import com.shreecon.lms.common.EmployeeDetailsView;
import com.shreecon.lms.interfaces.IMessageConstant;
import com.shreecon.lms.interfaces.LMSException;
import com.shreecon.lms.interfaces.persistance.ILeaveDAO;
import com.shreecon.lms.interfaces.persistance.LeaveDAOFactory;
import com.shreecon.lms.persistancy.hbm.LeaveAvailablity;

public class LeaveManagerValidator {

    private static String FROM_DATE = "From Date";
    private static String TO_DATE = "To Date";
    private static HashMap<String, String> LEAVE_TYPE = new HashMap<String, String>(2);
    static {
	LEAVE_TYPE.put("C", "C");
	LEAVE_TYPE.put("S", "S");
    }
    public void validate (String fromDate,String toDate,String typeOfLeave,EmployeeDetailsView view) throws LMSException {
	
	DateUtil.validateDate(fromDate,FROM_DATE);
	DateUtil.validateDate(toDate,TO_DATE);
	validateTypeOfLeave(typeOfLeave);
	ILeaveDAO leaveDAO = LeaveDAOFactory.getInstance().getLeaveDAO();
	List<LeaveAvailablity> leaveAvailablity = leaveDAO.findByUserId(Long.valueOf(view.getId()));
	
	System.out.println(leaveAvailablity);
	System.out.println(leaveAvailablity.size());
	for( LeaveAvailablity availablity : leaveAvailablity){
	    availablity.getLaNumDay();
	}
    }
    
    private void validateTypeOfLeave (String typeOfLeave) throws LMSException{
	String type = LEAVE_TYPE.get(typeOfLeave);
	if(type == null) {
	    throw new LMSException (IMessageConstant.INVALID_LEAVE_TYPE);
	}
    }
}
